home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / bbs / termv4.6 / extras / source / gtlayout-source.lha / LT_InitExit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-18  |  4.8 KB  |  234 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. /****** gtlayout.library/LT_Init ******************************************
  15. *
  16. *   NAME
  17. *    LT_Init -- Initialize user interface code.
  18. *
  19. *   SYNOPSIS
  20. *    LT_Init();
  21. *
  22. *    VOID LT_Init(VOID);
  23. *
  24. *   FUNCTION
  25. *    You need to initialize the user interface code only once,
  26. *    so it can set up its internals, open libraries, etc.
  27. *    The code has to be initialized before any user interface
  28. *    creation can take place.
  29. *
  30. *   NOTES
  31. *    This function is not present in the shared library, only
  32. *    in the link library. You need not and cannot invoke it in
  33. *    the shared library.
  34. *
  35. *   SEE ALSO
  36. *    gtlayout.library/LT_Exit
  37. *
  38. ******************************************************************************
  39. *
  40. */
  41.  
  42. BOOL LIBENT
  43. LT_Init()
  44. {
  45. #ifndef LINK_LIB
  46.     SysBase = *(struct ExecBase **)4;
  47. #endif    // LINK_LIB
  48.  
  49.     if(SysBase->LibNode.lib_Version < 37)
  50.         return(FALSE);
  51.     else
  52.     {
  53.         STATIC struct { STRPTR Name; APTR *Library; } InitTable[] =
  54.         {
  55.             "intuition.library",    (APTR *)&IntuitionBase,
  56.             "graphics.library",        (APTR *)&GfxBase,
  57.             "utility.library",        (APTR *)&UtilityBase,
  58.             "gadtools.library",        (APTR *)&GadToolsBase,
  59.             "keymap.library",        (APTR *)&KeymapBase,
  60.             "locale.library",        (APTR *)&LocaleBase
  61.         };
  62.  
  63.         LONG i;
  64.  
  65.         V39 = (SysBase->LibNode.lib_Version >= 39);
  66.         V40 = (SysBase->LibNode.lib_Version >= 40);
  67.  
  68.         for(i = 0 ; i < NUMELEMENTS(InitTable) ; i++)
  69.             *InitTable[i].Library = OpenLibrary(InitTable[i].Name,37);
  70.  
  71.         if(IntuitionBase && GfxBase && UtilityBase && GadToolsBase && KeymapBase)
  72.         {
  73.             if(LocaleBase)
  74.                 LTP_Locale = OpenLocale(NULL);
  75.  
  76.             if(LTP_ImageClass = MakeClass(NULL,IMAGECLASS,NULL,sizeof(ImageInfo),0))
  77.             {
  78.                 LTP_ImageClass->cl_Dispatcher.h_Entry = (HOOKFUNC)LTP_ImageDispatch;
  79.  
  80. #ifdef DO_LEVEL_KIND
  81.                 if(LTP_LevelClass = MakeClass(NULL,IMAGECLASS,NULL,sizeof(LevelImageInfo),0))
  82.                 {
  83.                     LTP_LevelClass->cl_Dispatcher.h_Entry = (HOOKFUNC)LTP_LevelClassDispatcher;
  84. #else
  85.                 {
  86. #endif    /* DO_LEVEL_KIND */
  87.  
  88. #if defined(DO_POPUP_KIND) && defined(DO_BOOPSI_KIND)
  89.                     if(LTP_PopupClass = MakeClass(NULL,GADGETCLASS,NULL,sizeof(PopInfo),0))
  90.                     {
  91.                         LTP_PopupClass->cl_Dispatcher.h_Entry = (HOOKFUNC)LTP_PopupClassDispatcher;
  92. #else
  93.                     {
  94. #endif    // DO_POPUP_KIND
  95.  
  96. #if defined(DO_TAB_KIND) && defined(DO_BOOPSI_KIND)
  97.                         if(LTP_TabClass = MakeClass(NULL,GADGETCLASS,NULL,sizeof(TabInfo),0))
  98.                         {
  99.                             LTP_TabClass->cl_Dispatcher.h_Entry = (HOOKFUNC)LTP_TabClassDispatcher;
  100. #else
  101.                         {
  102. #endif    // DO_TAB_KIND
  103.  
  104. #ifdef DO_PICKSHORTCUTS
  105.                             InitSemaphore(<P_KeySemaphore);
  106.  
  107.                             if(LTP_Keys[0] = (UBYTE *)AllocMem(512,MEMF_ANY|MEMF_CLEAR))
  108.                             {
  109. #else
  110.                             {
  111. #endif    /* DO_PICKSHORTCUTS */
  112.                                 InitSemaphore(<P_LockSemaphore);
  113.  
  114.                                 NewList((struct List *)<P_LockList);
  115.                                 NewList((struct List *)<P_EmptyList);
  116.  
  117.                                 return(TRUE);
  118.                             }
  119.                         }
  120.                     }
  121.                 }
  122.             }
  123.         }
  124.  
  125.         LT_Exit();
  126.  
  127.         return(FALSE);
  128.     }
  129. }
  130.  
  131.  
  132. /*****************************************************************************/
  133.  
  134.  
  135. /****** gtlayout.library/LT_Exit ******************************************
  136. *
  137. *   NAME
  138. *    LT_Exit -- Clean up user interface allocations
  139. *
  140. *   SYNOPSIS
  141. *    LT_Exit();
  142. *
  143. *    VOID LT_Exit(VOID);
  144. *
  145. *   FUNCTION
  146. *    When you are finished with user interface creation and
  147. *    do not not need the code any more you should call this
  148. *    routine. It will free all the memory allocated by
  149. *    LT_Init(), close libraries, etc.
  150. *
  151. *   INPUTS
  152. *    none
  153. *
  154. *   RESULT
  155. *    none
  156. *
  157. *   NOTES
  158. *    This function is not present in the shared library, only
  159. *    in the link library. You need not and cannot invoke it in
  160. *    the shared library.
  161. *
  162. *   SEE ALSO
  163. *    gtlayout.library/LT_Init
  164. *
  165. ******************************************************************************
  166. *
  167. */
  168.  
  169. VOID LIBENT
  170. LT_Exit()
  171. {
  172.     if(SysBase && SysBase->LibNode.lib_Version >= 37)
  173.     {
  174. #ifdef DO_PICKSHORTCUTS
  175.         FreeMem(LTP_Keys[0],512);
  176.         LTP_Keys[0] = LTP_Keys[1] = NULL;
  177. #endif
  178.  
  179. #ifdef DO_LEVEL_KIND
  180.         if(LTP_LevelClass)
  181.         {
  182.             FreeClass(LTP_LevelClass);
  183.             LTP_LevelClass = NULL;
  184.         }
  185. #endif    /* DO_LEVEL_KIND */
  186.  
  187. #if defined(DO_POPUP_KIND) && defined(DO_BOOPSI_KIND)
  188.         if(LTP_PopupClass)
  189.         {
  190.             FreeClass(LTP_PopupClass);
  191.             LTP_PopupClass = NULL;
  192.         }
  193. #endif    // DO_POPUP_KIND
  194.  
  195. #if defined(DO_TAB_KIND) && defined(DO_BOOPSI_KIND)
  196.         if(LTP_TabClass)
  197.         {
  198.             FreeClass(LTP_TabClass);
  199.             LTP_TabClass = NULL;
  200.         }
  201. #endif    // DO_TAB_KIND
  202.  
  203.         if(LTP_ImageClass)
  204.         {
  205.             FreeClass(LTP_ImageClass);
  206.             LTP_ImageClass = NULL;
  207.         }
  208.  
  209.         if(LTP_Locale)
  210.         {
  211.             CloseLocale(LTP_Locale);
  212.             LTP_Locale = NULL;
  213.         }
  214.  
  215.         CloseLibrary(LocaleBase);
  216.         LocaleBase = NULL;
  217.  
  218.         CloseLibrary(KeymapBase);
  219.         KeymapBase = NULL;
  220.  
  221.         CloseLibrary(GadToolsBase);
  222.         GadToolsBase = NULL;
  223.  
  224.         CloseLibrary(UtilityBase);
  225.         UtilityBase = NULL;
  226.  
  227.         CloseLibrary(GfxBase);
  228.         GfxBase = NULL;
  229.  
  230.         CloseLibrary(IntuitionBase);
  231.         IntuitionBase = NULL;
  232.     }
  233. }
  234.